package com.kuang;

/**
 * ClassName: TestLambda
 * Description:
 * Date: 2021/3/16 15:12
 * Company: TravelSky
 *
 * @author YangXin
 */
public class TestLambda {

    static class Like2 implements ILike {
        @Override
        public void lambda() {
            System.out.println("Lambda2表达式...");
        }
    }

    public static void main(String[] args) {
        //推导Lambda表达式
        ILike iLike = new Like();
        iLike.lambda();

        iLike = new Like2();
        iLike.lambda();

        //局部内部类
        class Like3 implements ILike {
            @Override
            public void lambda() {
                System.out.println("Lambda3表达式...");
            }
        }

        iLike = new Like3();
        iLike.lambda();

        //匿名内部类
        iLike = new Like(){
            @Override
            public void lambda() {
                System.out.println("Lambda4表达式...");
            }
        };
        iLike.lambda();

        //用lambda简化
        iLike = ()->{
            System.out.println("Lambda5表达式...");
        };
        iLike.lambda();

        iLike = ()-> System.out.println("Lambda6表达式...");
        iLike.lambda();

    }
}

interface ILike {
    void lambda();
}

class Like implements ILike {
    @Override
    public void lambda() {
        System.out.println("Lambda1表达式...");
    }
}
